10  ' 7coins.bas - FreeWare 2005 from Aruba
20 GOTO 130 ' begin
30 SAVE"7coins",A:LIST-130      
40 GOTO 560  ' get key
50 GOTO 600  ' selects line
60 GOTO 700  ' bad select
70 GOTO 770  ' draw star
80 GOTO 930  ' convert 47 - 57 to 0 - 10
90 GOTO 1050 ' check for legal select
100 GOTO 1280 ' convert T to x y position
110 GOTO 1370 ' you solved it
120 ' begin
130 DEFSTR Q:DEFINT C-L,X,Y:SCREEN 9:CLS
140 DIM P(8):Q=MKI$(0):DIM C(800)
150 CIRCLE(16,16),14,15:PAINT(16,16),15:GET(0,0)-(32,32),C
160 CLS:GOSUB 70:COLOR 11,0
170 LOCATE 1,1:PRINT "THE 7 COINS PUZZLE"
180 LOCATE 3,1:PRINT "The object is to place a"
190 LOCATE 4,1:PRINT "coin at all the vertices"
200 LOCATE 5,1:PRINT "but one of the star."
210 LOCATE 3,40:PRINT "When placing any coin you should"
220 LOCATE 4,40:PRINT "move it along a free line, and"
230 LOCATE 5,40:PRINT "put it down at the end of that line."
240 LOCATE 18,1:PRINT "A line is called free if"
250 LOCATE 19,1:PRINT "there is no coin at"
260 LOCATE 20,1:PRINT "either of its endpoints.":COLOR 12,0
270 LOCATE 23,1:PRINT "R or r to restart,"
280 LOCATE 24,1:PRINT "anytime in the game.";:COLOR 11,0
290 LOCATE 18,40:PRINT "Good luck, and enjoy this little"
300 LOCATE 19,40:PRINT "puzzle in GW-BASIC, made for you"
310 LOCATE 20,40:PRINT "by Eric F. Tchong, from sunny Aruba."
320 LOCATE 24,40:PRINT "Press any key ...";
330 PUT(403,103),C,PSET:GOSUB 40:CLS
340 LOCATE 1,1:PRINT"THIS is an example"
350 LOCATE 2,1:PRINT "of a solved puzzle..."
360 GOSUB 70 ' draw star and 7 coins
370 PUT(166,1)  ,C,PSET:PUT(302,1)  ,C,PSET ' 1 2
380 PUT(65,103) ,C,PSET:PUT(403,103),C,PSET ' 8 3
390 PUT(65,203) ,C,PSET:PUT(403,203),C,PSET ' 7 4
400 PUT(166,307),C,PSET:COLOR 12,0          ' 6
410 LOCATE 23,1:PRINT "Esc to exit program,"
420 LOCATE 24,1:PRINT "anytime in the game.";:COLOR 11,0
430 LOCATE 24,44:PRINT "Press any key to start ...";:GOSUB 40
440 ' draw board
450 CLS:SW=0:GOSUB 70 ' draw star
460 FOR A=1 TO 8:P(A)=0:NEXT
470 LOCATE 1,1:PRINT "THE 7 COINS PUZZLE"
480 GOSUB 50 ' solver selects line
490 IF SW=1 THEN 450
500 GOSUB 90 ' check if OK
510 IF HM=0 THEN GOSUB 60:GOTO 480
520 P(T)=1:GOSUB 100:PUT(X,Y),C,PSET:CM=0
530 FOR A=1 TO 8:CM=CM+P(A):NEXT
540 IF CM=7 THEN GOSUB 110:GOTO 430 ELSE GOTO 480
550 ' get key
560 LSET Q=MKI$(0):SW=0
570 WHILE CVI(Q)=0:MID$(Q,1)=INKEY$:WEND
580 IF ASC(Q)=27 THEN 1260 ELSE RETURN
590 ' selects line
600 LOCATE 4,54:PRINT "Select  line"
610 GOSUB 40:F=ASC(Q):LOCATE 5,54:PRINT Q
620 IF ASC(Q)=82 OR ASC(Q)=114 THEN SW=1:RETURN ' R or r to restart
630 IF F<49 OR F>57 THEN GOSUB 60:GOTO 610
640 GOSUB 80:K=F
650 IF ASC(Q)=82 OR ASC(Q)=114 THEN SW=1:RETURN ' R or r to restart
660 GOSUB 40:T=ASC(Q):LOCATE 5,57:PRINT Q
670 IF T<49 OR T>57 THEN GOSUB 60:GOTO 660
680 F=T:GOSUB 80:U=F:F=K:T=U:RETURN
690 ' bad select
700 BEEP
710 FOR D=1 TO 12
720  LOCATE 6,54:PRINT "Bad select":SOUND .49,.2
730  LOCATE 6,54:PRINT "          ":SOUND .49,.2
740 NEXT
750 LOCATE 5,54:PRINT "    ":RETURN
760 ' draw star
770 COLOR 14,0
780 LINE (200,20)-(200,320)  ' 1-6
790 LINE (300,20)-(300,320)  ' 2-5
800 LINE (100,120)-(400,120) ' 8-3
810 LINE (100,220)-(400,220) ' 7-4
820 LINE (200,20)-(400,220)  ' 1-4
830 LINE (100,120)-(300,320) ' 8-5
840 LINE (100,220)-(300,20)  ' 7-2
850 LINE (200,320)-(400,120) ' 6-3
860 COLOR 12,0
870 LOCATE 2,27 :PRINT "1" :LOCATE 2,36 :PRINT "2"
880 LOCATE 11,13:PRINT "8" :LOCATE 11,50:PRINT "3"
890 LOCATE 15,13:PRINT "7" :LOCATE 15,50:PRINT "4"
900 LOCATE 24,27:PRINT "6";:LOCATE 24,36:PRINT "5";
910 COLOR 11,0:RETURN
920 ' convert 47 - 57 to 0 - 10
930 IF F=47 THEN F=10:RETURN
940 IF F=48 THEN F=0:RETURN
950 IF F=49 THEN F=1:RETURN
960 IF F=50 THEN F=2:RETURN
970 IF F=51 THEN F=3:RETURN
980 IF F=52 THEN F=4:RETURN
990 IF F=53 THEN F=5:RETURN
1000 IF F=54 THEN F=6:RETURN
1010 IF F=55 THEN F=7:RETURN
1020 IF F=56 THEN F=8:RETURN
1030 IF F=57 THEN F=9:RETURN
1040 ' check for legal select
1050 IF F=T THEN 1220
1060 IF F=1 AND T=4 THEN 1230 ' 1 4
1070 IF F=4 AND T=1 THEN 1230 ' 4 1
1080 IF F=1 AND T=6 THEN 1230 ' 1 6
1090 IF F=6 AND T=1 THEN 1230 ' 6 1
1100 IF F=2 AND T=5 THEN 1230 ' 2 5
1110 IF F=5 AND T=2 THEN 1230 ' 5 2
1120 IF F=2 AND T=7 THEN 1230 ' 2 7
1130 IF F=7 AND T=2 THEN 1230 ' 7 2
1140 IF F=3 AND T=6 THEN 1230 ' 3 6
1150 IF F=6 AND T=3 THEN 1230 ' 6 3
1160 IF F=3 AND T=8 THEN 1230 ' 3 8
1170 IF F=8 AND T=3 THEN 1230 ' 8 3
1180 IF F=4 AND T=7 THEN 1230 ' 4 7
1190 IF F=7 AND T=4 THEN 1230 ' 7 4
1200 IF F=5 AND T=8 THEN 1230 ' 5 8
1210 IF F=8 AND T=5 THEN 1230 ' 8 5
1220 HM=0:RETURN
1230 IF P(F)=0 AND P(T)=0 THEN HM=1:RETURN
1240 GOTO 1220
1250 ' exit
1260 SCREEN 0,0,0:CLS:END
1270 ' convert T to X,  Y positions
1280 IF T=1 THEN X=166:Y=1  :RETURN
1290 IF T=2 THEN X=302:Y=1  :RETURN
1300 IF T=3 THEN X=403:Y=103:RETURN
1310 IF T=4 THEN X=403:Y=203:RETURN
1320 IF T=5 THEN X=302:Y=307:RETURN
1330 IF T=6 THEN X=166:Y=307:RETURN
1340 IF T=7 THEN X= 65:Y=203:RETURN
1350 IF T=8 THEN X= 65:Y=103:RETURN
1360 ' you solved it
1370 BEEP:COLOR 15,0
1380 FOR D=1 TO 12
1390  LOCATE 6,54:PRINT "Bravo! You solved it!!!":SOUND .49,.2
1400  LOCATE 6,54:PRINT "                       ":SOUND .49,.2
1410 NEXT:COLOR 11,0
1420 LOCATE 5,54:PRINT "    ":RETURN
1430 GOSUB 40:GOTO 450
